<%-- 
    Document   : formAjoutCreneau3
    Created on : 29 mars 2013, 15:52:08
    Author     : ali
--%>

<%@page import="EDT.api.API"%>
<%@page import="EDT.obj.Ec"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.HashMap"%>
<%@page import="EDT.obj.Formation"%>
<%@page import="EDT.obj.Intervenant"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>Ajouter Un Creneau </title>
            <link rel="stylesheet" href="Accueil.css" />
            <link rel="SHORTCUT ICON" href="./edt.jpg" />
            
            <style type="text/css"> 
		
			dl.defs{ margin: 10px 0 10px 40px; }
			dl.defs dt{ font-weight: bold; line-height: 20px; margin: 10px 0 0 0; }
			dl.defs dd{ margin: -20px 0 10px 160px; padding-bottom: 10px; border-bottom: solid 1px #eee;}

			.wrapper{ background-color: #ffffff; width: 800px; border: solid 1px #eeeeee; padding: 20px; margin: 0 auto; }
			#tabs{ margin: 20px -20px; border: none; }
			#tabs, #ui-datepicker-div, .ui-datepicker{ font-size: 85%; }
			.clear{ clear: both; }

            </style> 
		
		<link rel="stylesheet" media="all" type="text/css" href="http://code.jquery.com/ui/1.10.0/themes/smoothness/jquery-ui.css" />
		<link rel="stylesheet" media="all" type="text/css" href="jquery-ui-timepicker-addon.css" />
		
		<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
		<script type="text/javascript" src="http://code.jquery.com/ui/1.10.0/jquery-ui.min.js"></script>
		<script type="text/javascript" src="jquery-ui-timepicker-addon.js"></script>
		<script type="text/javascript" src="jquery-ui-sliderAccess.js"></script>
		<script type="text/javascript">
			
			$(function(){
				$('#tabs').tabs();
		
				$('.example-container > pre').each(function(i){
					eval($(this).text());
				});
			});
                        
		</script>
            
            <script language="JavaScript">
 var  disabledDays;                       
                         $(document).ready(function(){ 
                             
                             disabledDays=JourF();
                         });
               
               $(document).ready(function () {
    $('#rest_example_x').datetimepicker({
        dateFormat: "dd-mm-yy",
	minDate: new Date(document.getElementsByName('anneeMin')[0].value),
	maxDate: new Date(parseInt(document.getElementsByName('annee')[0].value)+1,07,31,17,59),
        hourMin: 8,
	hourMax: 19,
        addSliderAccess: true,
	sliderAccessArgs: { touchonly: false },
        altField: "#alt_example_1_alt",
        constrainInput: true,
        beforeShowDay: noWeekendsOrHolidays
    }
 
);

});


/* create an array of days which need to be disabled */
//var disabledDays = ["5-1-2013"];
//var disabledDays = document.getElementById("jourf").value;
 
//alert(disabledDays);

/* utility functions */
function nationalDays(date) {
	var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
	//console.log('Checking (raw): ' + m + '-' + d + '-' + y);
	for (i = 0; i < disabledDays.length; i++) {
		if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1 /* || new Date() > date */) {
			//console.log('bad:  ' + (m+1) + '-' + d + '-' + y + ' / ' + disabledDays[i]);
			return [false];
		}
	}
	//console.log('good:  ' + (m+1) + '-' + d + '-' + y);
	return [true];
}
function noWeekendsOrHolidays(date) {
	//var noWeekend = jQuery.datepicker.noWeekends(date);
	//return noWeekend[0] ? nationalDays(date) : noWeekend;
        return nationalDays(date);

}

//function JourF(an){
    function JourF(){
  
    //var jfAnneea =  JoursFeries(an);
    //var jfAnneeb =  JoursFeries((parseInt(an)+1));
    
    
    //var tab = new Array();
    
    var resulta = document.getElementsByName('jourf')[0].value;
    
   var tab = resulta.split(",");
    
    /*
    for(var i= 0; i < jfAnneea.length; i++)
    {
        tab.push(jfAnneea[i].getMonth()+"-"+jfAnneea[i].getDate()+"-"+jfAnneea[i].getFullYear());
    }
    
    for(var i= 0; i < jfAnneeb.length; i++)
    {
        tab.push(jfAnneeb[i].getMonth()+"-"+jfAnneeb[i].getDate()+"-"+jfAnneeb[i].getFullYear());
    }*/
    
    return tab;
}
/*
function JoursFeries (an){
    var JourAn = new Date(an, "00", "01")
    var FeteTravail = new Date(an, "04", "01")
    var Victoire1945 = new Date(an, "04", "08")
    var FeteNationale = new Date(an,"06", "14")
    var Assomption = new Date(an, "07", "15")
    var Toussaint = new Date(an, "10", "01")
    var Armistice = new Date(an, "10", "11")
    var Noel = new Date(an, "11", "25")
    //var SaintEtienne = new Date(an, "11", "26")
    var G = an%19
    var C = Math.floor(an/100)
    var H = (C - Math.floor(C/4) - Math.floor((8*C+13)/25) + 19*G + 15)%30
    var I = H - Math.floor(H/28)*(1 - Math.floor(H/28)*Math.floor(29/(H + 1))*Math.floor((21 - G)/11))
    var J = (an*1 + Math.floor(an/4) + I + 2 - C + Math.floor(C/4))%7
    var L = I - J
    var MoisPaques = 3 + Math.floor((L + 40)/44)
    var JourPaques = L + 28 - 31*Math.floor(MoisPaques/4)
    var Paques = new Date(an, MoisPaques-1, JourPaques)
    //var VendrediSaint = new Date(an, MoisPaques-1, JourPaques-2)
    var LundiPaques = new Date(an, MoisPaques-1, JourPaques+1)
    var Ascension = new Date(an, MoisPaques-1, JourPaques+39)
    var Pentecote = new Date(an, MoisPaques-1, JourPaques+49)
    var LundiPentecote = new Date(an, MoisPaques-1, JourPaques+50)
    return new Array(JourAn, LundiPaques, FeteTravail, Victoire1945, Ascension, LundiPentecote, FeteNationale, Assomption, Toussaint, Armistice, Noel)
}
*/
         </script>
   
    </head>

    <body>    
        
    <section>
        
        <%
          
        String form ="";
                           
        ArrayList<Formation> formation = new ArrayList<Formation>();
        
        
        
        formation = (ArrayList<Formation> ) session.getAttribute("formation");
        
        
                
        String s =request.getParameter("formation");
                
        String pp = request.getParameter("promo");
       
        int periode = Integer.parseInt(request.getParameter("periode"));
        
        int idp = Integer.parseInt(pp);
                
        int annee = 0;
        int fid = Integer.parseInt(s);
         
        int nbrgrp = 0;
              
        for (Formation f : formation)
        if (f.getId() == fid){
        HashMap<Integer, Integer> hashMap = f.getLesPromos();
        for (Integer mapKey : hashMap.keySet()){
             if (mapKey == idp )
                annee =hashMap.get(mapKey);
                nbrgrp = f.getNbrGpPromo().get(idp);
                
             }
        }

        
        String key = (String) session.getAttribute("key");    
              
        form +="<form method='POST' action='AjoutCreneau4.do' target='section'>\n";
        form += "<div class='commentaire'>\n";
        form += "<fieldset>";
               
        form += "<legend>    Choisissez une date :   </legend>";
        
        form += "<input type='hidden' name='key' value='"+key+"'/>";

        Calendar cal1 = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();
        Date dateCourante = new Date();
        cal1.setTime(dateCourante);
        cal2.set(annee, 9, 1);
        DateFormat dateFormat = new SimpleDateFormat("yyyy,MM,dd");
        
       /*  if(cal1.after(cal2))
        form += "<input type='hidden' name='anneeMin' value='"+dateFormat.format(cal1.getTime())+"'/>";
        else */
        form += "<input type='hidden' name='anneeMin' value='"+annee+",09,01'/>";
            
        form += "<input type='hidden' name='annee' value='"+annee+"'/>";
        
        String jourFerie = API.getJourferie(annee);
        form += "<input type='hidden' name='jourf' value='"+jourFerie+"'/>";
        
        form += "<input type='hidden' id ='idpromo' name='promo' value='"+idp+"'/>";
            
        form += "<input type='hidden' name='nbrPeriode' value='"+request.getParameter("nbrPeriode")+"'/>";
        
        ArrayList<Ec> ecs = EDT.api.API.getEC(fid,Integer.parseInt(request.getParameter("periode")));
        form += "Les ECs :   <select name='ec'>";
        for (Ec ec : ecs)
        form += "<option value='"+ec.getId()+"'>"+ec.getNom()+"</option>";
        form += "</select><br/><br/>";
                
        form += "Type :   <select name='type'>";
        form += "<option value='cm'>Cours</option>";
        form += "<option value='td' selected>TD</option>";
        form += "<option value='tp'>TP</option>";
        form += "</select><br/><br/>";
        
        //int nbrgrp = EDT.api.API.getNbrGp(idp);
        
        form += "Numéro du groupe :<select name='gp'>";
        for (int i =1; i<= nbrgrp; i++){
        form += "<option value='"+i+"'>"+i+"</option>";    
        }
        form += "</select><br/><br/>";
        
        
        
        String datesPeriode= API.getDateOfPeriode(idp, periode);
        form += "<div class'example-container'>"; 
        form += "<label style='color:red;'> Attention </label>vous devez choisir une date qui correspond à la periode <label style='color:red;'> "+periode+" </label> de l'année entre "+datesPeriode+" <br/><br/>";
        form += "La date : <input type='text' name='dateHeure' id='rest_example_x' value='' onclick='' /><br/><br/>";
        form +="L'heure  : <input style='cursor: pointer;' name='alt_example_1_alt' id='alt_example_1_alt' value='' type='text'><br/><br/>";
        form += "</div>";
                             
        form += "durer :<select name='durer'>";
        form += "    <option value='30'>30m</option>";
        form += "    <option value='45'>45m</option>";
        form += "    <option value='60'>1h</option>";
        form += "    <option value='75'>1h15</option>";
        form += "    <option value='90'>1h30</option>";
        form += "    <option value='105'>1h45</option>";
        form += "    <option value='120'>2h</option>";
        
        form += "</select><br/><br/>";
        
        form += "nombre de créneau :<select name='nbrCr'>";
        for (int i=1; i<=10; i++)
        form += "    <option value='"+i+"'>"+i+"</option>";
        form += "</select><br/><br/>";

        form += "Type de visibilité :<select name='visible'>";
        form += "    <option value='true'>public</option>";
        form += "    <option value='fals'>privé</option>";
        form += "</select><br/><br/>";
        
        
        form += "<input type='submit' value='valider'/><br/>";
        
        out.println(form);
        session.removeAttribute("formation");
                
%>
        
     
    <html:errors/> 
    



    </fieldset>
    
        
    </div>

    </form>
  
</section>

    
    </body>
</html>
